<template>
  <van-picker
    title="更改性别"
    show-toolbar
    :default-index="gender"
    :columns="columns"
    @confirm="onConfirm"
    @cancel="onCancel"
  />
</template>

<script>
import { editUserProfileAPI } from '@/api'

export default {
  props: {
    gender: {
      type: [String, Number],
      required: true
    }
  },
  data() {
    return { columns: ['男', '女'] }
  },
  methods: {
    async onConfirm(value, index) {
      try {
        this.$toast.loading({
          message: '桥豆麻袋.....'
        })
        await editUserProfileAPI({
          gender: index
        })
        this.$emit('update:gender', index)
        this.$emit('close')
        this.$toast.success('ojbk')
      } catch (error) {
        this.$toast.fail('兄弟  你嘎了')
      }
    },
    onCancel() {
      this.$emit('close')
    }
  }
}
</script>

<style></style>
